// ****************************************************************
// Copyright 2012, Stephan Burguchev
// e-mail: me@sburg.net
// ****************************************************************
// *
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;

namespace Updater.Wpf.Utils
{
    public abstract class ConverterMarkupExtension<T>
        : MarkupExtension,
          IValueConverter
        where T : class, new()
    {
        private static T converter;

        public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture);
        public abstract object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture);

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (converter == null)
            {
                converter = new T();
            }

            return converter;
        }
    }
}
